package com.rui.patterns.interpreter;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : Plus
 * @createTime : [2022/2/25 15:42]
 * @description : [描述该类的功能]
 */

public class Minus extends AbstractExpression {

    /**
     * +号左边的表达式
     */
    private AbstractExpression left;

    /**
     * +号右边的表达式
     */
    private AbstractExpression right;

    public Minus(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {
        //将左边表达式的结果和右边表达式的结果相减
        return left.interpret(context) - right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + " - " + right.toString() + ")";
    }
}
